import java.io.*;
import java.util.*;


// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class code3 {
    public static Read in = new Read();
    public static PrintWriter out = new PrintWriter(new BufferedWriter(
            new OutputStreamWriter(System.out)));
    public static void main(String[] args) throws IOException {
        int n = in.nextInt();
        int m = in.nextInt();
        long[][] arr = new long[n][m];

        long[] row = new long[m];
        long[] col = new long[n];

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                arr[i][j] = in.nextLong();
                col[i] += arr[i][j];//这一列的
                row[j] += arr[i][j];//这一行的
            }
        }

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                out.print(col[i] + row[j] - arr[i][j] + " ");
            }
            out.println();
        }
        out.close();

    }
}

class Read {
    StringTokenizer st = new StringTokenizer("");
    BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
    String next() throws IOException {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(bf.readLine());
        }
        return st.nextToken();
    }

    String nextLine() throws IOException {
        return bf.readLine();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }
}